-
Notifications
You must be signed in to change notification settings - Fork 155
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Let prompts choose to repaint on enter #627
Conversation
If reedline is going to support a transient prompt, which would be totally rad, I'd love to see an example in this repo that shows folks how to make a basic one. |
So it looks like |
Okay, looks like the line buffer was being cleared by the time the Looks like syntax highlighting works too. The above screenshot is just the |
Yes, another example would be best. It also has to be confirmed that your change doesn't break anything else or the other examples. Also, since you're pulling the history, you need to make sure it works with text-based history and sqlite-based history, both supported by reedline. |
So I added some more stuff to the transient prompt example (completer, highlighter, hinter, validator) to confirm that they're working. I assume that if this PR's accepted, all that extra stuff will have to be removed right before this PR's merged? |
I ran this PR example. I'm not sure what it's supposed to do or how to make it work. I just get this
|
My bad, I added a custom validator (line 80) so it only goes to the next line if you end your input with a |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for giving this a shot and working up an example and doing due diligence on the testing.
From a long term maintenance perspective I think this API is a bit too bug prone and can cause confusion.
I ended up going with a |
I was getting ready to object to the |
Wait a second, now that I look at these unwraps, most of them are in tests, which is fine. I found 10 that are not in tests that we need to fix. @ysthakur, would you mind adding error handling to the one you have in engine.rs? I really don't think we want to continue adding unwraps in our code. |
Perhaps if the result of The whole |
By the way, in case you're planning on getting rid of the |
good point. sounds like something for a followup pr, if anyone is interested. hint hint. 😆 |
I made another branch to try using a Edit: I managed to make it not use |
src/engine.rs
Outdated
/// Set a different prompt to be used after submitting each line | ||
#[must_use] | ||
pub fn with_transient_prompt(mut self, transient_prompt: Box<dyn Prompt>) -> Self { | ||
self.transient_prompt = Some(Arc::from(Mutex::from(transient_prompt))); | ||
self | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you can get by with this fn (mut self, Box<>) -> Self
signature, then I don't think the whole Arc<Mutex<Box<>>>
is needed, right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's not, but self.repaint(self.transient_prompt.as_ref())
requires mutably and immutably borrowing self
at the same time, and the only way to get around it that I can think of is by moving the transient_prompt
field out of self
, replacing it with None
, calling repaint
, and then moving transient_prompt
back into self
. That feels like a hack, though. Here's a diff (from a separate branch) showing it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@sholderbach Just wanted to nudge you in case you didn't see my previous comment (also, I just pushed a commit to use Option.take()
instead of std::mem::replace
)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ysthakur sorry for not getting back to you!
Yes I like the variant with .take()
. To me that is pretty idiomatic.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@sholderbach Great, just merged that other branch into this PR's branch
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for sticking with us!
Let's land this, so the road is clear to figure out the best way to configure this in nushell.
(with https://github.com/nushell/nushell/blob/ba6d8ad2617c2100021d6e3c949c0b9088f2667b/Cargo.toml#L167 you can just cargo update -p reedline
to get the latest unreleased version for testing)
Thanks for merging this PR, and all the feedback! |
Can't wait to see what this looks like in nushell. It should be interesting. Good work @ysthakur! |
This PR goes towards addressing #348. It adds
fn repaint_on_enter(&self) -> bool
to thePrompt
trait so that a prompt can choose to be repainted on enter. I figured an option could be added to$env.config
on the Nushell side to enable a transient prompt. After that, the hooks described in this issue will hopefully start working.